package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Address;
import com.itheima.service.AddressManagementService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/addressManagement")
@RestController
public class AddressManagementController {
    @Reference
    private AddressManagementService addressManagementService;

    @RequestMapping("/findPage")
    public Result findPage(@RequestBody QueryPageBean queryPageBean){
        PageResult page = addressManagementService.findPage(queryPageBean);
        return new Result(true,"查询体检机构成功",page);
    }
    @RequestMapping("/findById")
    public Result findById(Integer id){
      try {
          Address address= addressManagementService.findById(id);
          return new Result(true,"弹出编辑信息成功",address);
      }catch (Exception e){
          e.printStackTrace();
          return new Result(false,"弹出编辑信息失败");
      }
    }
    @RequestMapping("/delById")
    public Result delById(Integer id){
       try {
           addressManagementService.delById(id);
           return new Result(true,"删除体检机构成功");
       }catch (Exception e){
           e.printStackTrace();
           return new Result(false,"删除体检机构失败");
       }
    }
    @RequestMapping("/add")
    public Result add(@RequestBody Address address){
        try {
            addressManagementService.add(address);
            return new Result(true,"添加体检机构成功");
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"添加体检机构失败");
        }
    }
    @RequestMapping("/update")
    public Result update(@RequestBody Address address) {
       try {
           addressManagementService.update(address);
           return new Result(true,"编辑机构信息成功");
       }catch (Exception e){
           e.printStackTrace();
           return new Result(false,"修改失败");
       }
    }
}
